﻿using DongFangGuoKai.WCSPlatform.WebApi.Utils.UtilModel;
using Microsoft.AspNetCore.Mvc;

namespace DongFangGuoKai.WCSPlatform.WebApi.Extensions
{
    public static class ControllerBaseExtension
    {
        public static WCSApiResponse Success(this ControllerBase controllerBase)
        {
            return new WCSApiResponse()
            {
                Code = 0,
                Data = true,
                Msg = "成功",
            };
        }
        public static WCSApiResponse Success(this ControllerBase controllerBase, string msg)
        {
            return new WCSApiResponse()
            {
                Code = 0,
                Data = true,
                Msg = msg,
            };
        }
        public static WCSApiResponse Success(this ControllerBase controllerBase, object data)
        {
            return new WCSApiResponse()
            {
                Code = 0,
                Data = data,
                Msg = "成功",
            };
        }
        
        public static WCSApiResponse Success(this ControllerBase controllerBase, object data, string msg)
        {
            return new WCSApiResponse()
            {
                Code = 0,
                Data = data,
                Msg = msg,
            };
        }
    
        public static WCSApiResponse Success(this ControllerBase controllerBase, int code,object data,string msg)
        {
            return new WCSApiResponse()
            {
                Code = code,
                Data = data,
                Msg = msg,
            };
        }
        public static WCSApiResponse Fail(this ControllerBase controllerBase, string msg)
        {
            return new WCSApiResponse()
            {
                Code = 1,
                Data = false,
                Msg = msg,
            };
        }
        public static WCSApiResponse Fail(this ControllerBase controllerBase, object data, string msg)
        {
            return new WCSApiResponse()
            {
                Code = 1,
                Data = data,
                Msg = msg,
            };
        }
        public static WCSApiResponse Fail(this ControllerBase controllerBase, int code, object data, string msg)
        {
            return new WCSApiResponse()
            {
                Code = code,
                Data = data,
                Msg = msg,
            };
        }

        #region 异步版本

        public static async Task<WCSApiResponse> SuccessAsync(this ControllerBase controllerBase, string msg)
        {
            return await Task.Run(() =>
            {
                return new WCSApiResponse()
                {
                    Code = 0,
                    Data = true,
                    Msg = msg,
                };
            });
        }

        public static async Task<WCSApiResponse> SuccessAsync(this ControllerBase controllerBase, object data)
        {
            return await Task.Run(() =>
            {
                return new WCSApiResponse()
                {
                    Code = 0,
                    Data = data,
                    Msg = "成功",
                };
            });
        }

        public static async Task<WCSApiResponse> SuccessAsync(this ControllerBase controllerBase, object data, string msg)
        {
            return await Task.Run(() =>
            {
                return new WCSApiResponse()
                {
                    Code = 0,
                    Data = data,
                    Msg = msg,
                };
            });
        }

        public static async Task<WCSApiResponse> SuccessAsync(this ControllerBase controllerBase, int code, object data, string msg)
        {
            return await Task.Run(() =>
            {
                return new WCSApiResponse()
                {
                    Code = code,
                    Data = data,
                    Msg = msg,
                };
            });
        }

        public static async Task<WCSApiResponse> FailAsync(this ControllerBase controllerBase, string msg)
        {
            return await Task.Run(() =>
            {
                return new WCSApiResponse()
                {
                    Code = 1,
                    Data = false,
                    Msg = msg,
                };
            });
        }

        public static async Task<WCSApiResponse> FailAsync(this ControllerBase controllerBase, object data, string msg)
        {
            return await Task.Run(() =>
            {
                return new WCSApiResponse()
                {
                    Code = 500,
                    Data = data,
                    Msg = msg,
                };
            });
        }

        public static async Task<WCSApiResponse> FailAsync(this ControllerBase controllerBase, int code, object data, string msg)
        {
            return await Task.Run(() =>
            {
                return new WCSApiResponse()
                {
                    Code = code,
                    Data = data,
                    Msg = msg,
                };
            });
        }

        #endregion
    }
}
